package Lee_code;

public class Lee_1049_2 {
    public int findMaxForm(String[] strs, int m, int n) {
        int len = strs.length;
        int[][] dp = new int[m+1][n+1];

        for (int i=0; i< strs.length; i++){
            for (int j=m; j>=count_0(strs[i]); j--){
                for (int k=n; k>=count_1(strs[i]); k--){
                    dp[j][k] = Math.max(dp[j][k], dp[j-count_0(strs[i])][k-count_1(strs[i])]+1);
                }
            }
        }

        return dp[m][n];
    }
    public int count_1(String str){
        int count = 0;
        for (int i=0; i<str.length(); i++){
            if (str.charAt(i)=='0')
                count++;
        }
        return count;
    }

    public int count_0(String str){
        int count = 0;
        for (int i=0; i<str.length(); i++){
            if (str.charAt(i)=='0')
                count++;
        }
        return count;
    }

}
